#include <iostream>
#include "Logic.h"
using namespace std;

int getMin(int a, int b, int c, int d){
        if(a <= b){
                if(c <= d){
                        if(a <= c) return 1;
                        else return 3;
                }
                if(d <= c){
                        if(a <= d) return 1;
                        else return 4;
                }
        }
        else if(b <= a){
                if(c <= d){
                        if(b <= c) return 2;
                        else return 3;
                }
                if(d <= c){
                        if(b <= d) return 2;
                        else return 4;
                }
        }
        return 0;
}

int main(int argc, char *argv[]){
        if(argc > 1){
                srand48(atoi(argv[1]));
        }
        else {
                srand48(0);
        }
        Logic newlogic;
        while(newlogic.players[0]->getPScore() < 80 && newlogic.players[1]->getPScore() < 80 && newlogic.players[2]->getPScore() < 80 && newlogic.players[3]->getPScore() < 80){
                newlogic.startGame();
                newlogic.assignScores();
                newlogic.emptyDiscards();
                newlogic.Reset();
                
        }
        int pWin = getMin(newlogic.players[0]->getPScore(), newlogic.players[1]->getPScore(), newlogic.players[2]->getPScore(), newlogic.players[3]->getPScore());
        for(int i = 0; i < 4; i++){
                if(newlogic.players[i]->getPScore() == newlogic.players[pWin-1]->getPScore()){
                        cout << "Player " << i+1 << " wins!" << endl;
                }
        }
        
        return 0;

}
